<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body{
            margin: 0;/*去掉外边距*/
            background-image: url("imgs/loginbj.png");
            background-size: cover;/*设置封面*/
            background-repeat: no-repeat;
            text-align: center;/*页面内部的文本居中*/
        }
        h1{
            font-size: 72px;
            color: #21376c;
            margin-bottom: 0;
        }
        img{
            width: 100px;
        }
        h2{
            font-size: 32px;
            color:#21376c;
            margin-bottom: 0;
        }
    </style>
</head>
<body>
<div id="app" style="position: absolute;right: 150px;top: 100px">
    <h1>欢迎来到幸运酒店</h1>
<!--    <h2>LuckHotel</h2>-->
    <el-card style="width: 600px;height: 400px;margin: 50px auto;
    background-color: rgba(255,255,255,0.4);
               ">
        <!--label-width设置用户名这一列所占的宽度,如果不设置会显示在上面-->
        <el-form  style="width: 400px;margin: 50px auto;color: white">

            <el-form-item >
                <el-input type="text" prefix-icon="el-icon-user" v-model="user.username" placeholder="请输入用户名" ></el-input>
            </el-form-item>

            <el-form-item >
                <el-input type="password" prefix-icon="el-icon-lock" v-model="user.password" placeholder="请输入密码" ></el-input>
            </el-form-item>

            <el-form-item>
                <el-checkbox v-model="user.rem" style="position: relative;left: 90px;">记住密码</el-checkbox>

                <a href="javascript:void(0)" style="position: relative;left: 125px;text-decoration: none;color: #606266;">找回密码</a>
            </el-form-item>

            <el-form-item>
                <el-button style="position: relative;right: 10px;margin-right: 30px"
                           type="primary" @click="login()">登录</el-button>

                <el-button style="position: relative;right: 10px"
                           type="info" @click="login()" plain>用户注册</el-button>
            </el-form-item>


        </el-form>
    </el-card>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                user:{
                    username:"",
                    password:"",
                    rem:false
                },
                radio:'1'
            }
        },
        methods:{
            login() {
                axios.post("/login",v.user).then(function (response) {
                    if(response.data==1) {
                        location.href="admin.html";
                    }else if(response.data==2){
                        v.$message.error("用户名不存在！");
                    }else {
                        v.$message.error("密码错误！");
                    }
                })
            }
        },
        created:function () {
            let arr = document.cookie.split(";");
            for (let cookie of arr) {
                let cookieArr = cookie.split("=");
                let name =cookieArr[0].trim();
                let value = cookieArr[1];
                if(name=="username") {
                    this.user.username=value;
                }else if(name=="password") {
                    this.user.password=value;
                }
            }
        }
    })
</script>
</html>